<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>

        // 提供了一些内置对象  比如 Math  Date  Object   Array

        // Math对象为我们提供了很多数学方法,比如求最大值最小值


        console.log(Math.abs(-10));  //绝对值10

        // 向下取整(往小取)
        console.log(Math.floor(5.4));  //5
        console.log(Math.floor(5.6));   //5
        console.log(Math.floor(-5.6));  //-6

        // 向上取整(往大取)
        console.log(Math.ceil(5.4));  //6
        console.log(Math.ceil(5.6));  //6
        console.log(Math.ceil(-5.6));  //-5 
        // 取整不会四舍五入


        // 求最大最小值
        // 任意个数
        console.log(Math.max(1,5,3,4,9,7,6));  //9
        console.log(Math.min(1,5,3,4,9,7,6));  //1


        // Math.pow(x,y)求x的y次方

        console.log(Math.pow(2,31));  //2147483648

        // Math.sqrt()开方运算
        console.log(Math.sqrt(9));  //3
        console.log(Math.sqrt(3));  //1.7320508075688772


        // Math.round()四舍五入到整数
        console.log(Math.round(2.4));  //2
        console.log(Math.round(2.5));  //3

        // js四舍五入的缺陷:精度不够
        console.log(Math.round(3.4999999999999999999999999999999999));  //4
        console.log(3.4999999999999999999999999999999===3.5);  //true

        // 负数  五舍六入
        console.log(Math.round(-3.5));  //-3
        console.log(Math.round(-3.4));  //-4
        console.log(Math.round(-3.6));  //-5


        // Math.random()  随机数[0,1)
        console.log(Math.random());

        // [0,5]   整数
        console.log(Math.floor(Math.random()*6));
        console.log(Math.floor(Math.random()*6)+5);


        // 总结规律,任意范围的随机整数[min,max]
        // Math.floor(Math.random()*个数)+min;


    </script>
</body>
</html>